package cn.itcast.order.web;

import cn.itcast.order.config.PatternProperties;

import cn.itcast.order.service.OrderService;

import com.cwj.openfign.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Enumeration;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private OrderService orderService;
//
//   @Autowired
//    RestTemplate restTemplate;

//   这种方式实现热更新的配置更加的简单
   @Autowired
    PatternProperties patternProperties;

    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId, HttpServletRequest request, HttpServletResponse response) {
        String myheader1 = request.getHeader("myheader");
        System.out.println("获取到的请求头信息是"+myheader1);
        // 根据id查询订单并返回
        Order order = orderService.queryOrderById(orderId);
        return order;
    }

    @GetMapping("/data")
    public String getString(){
        System.out.println(patternProperties.getDataFormat());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patternProperties.getDataFormat());
        Date date = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(date);
        return format;
    }

}
